﻿<!DOCTYPE html>
<html>
<head>
    <title>绑定帐号</title>
    <link href="/SiteUI/Wechat/wechatBinding.css" rel="stylesheet" />
    <link href="/SiteUI/Base.css" rel="stylesheet" />
    <link href="/LiberUI/Style/LiberUI.css" rel="stylesheet" />
    <script src="/LiberUI/Scripts/jquery.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Base.js"></script>
</head>
<body>
    <script>
        SoBiz.Template("_wxBase");
    </script>
    <script type="text/html" section="PageBody">
        <div class="row" id="userInfo">
            <div class="col-lg-6 col-lg-offset-3">
                <img id="userInfo_headImg" src="/SiteUI/Imgs/logo-txt-little.png" />
                <div id="userInfo_tip"></div>
            </div>
        </div>
        <div class="row" id="wx-tab">
            <div class="col-lg-12 binding-fill"  >
                <input id="wx-phone" type="text" placeholder="请输入手机号" />
            </div>
            <div class="col-lg-12 binding-fill" >
                <input id="wx-pwd" type="password" placeholder="请输入密码" />
            </div>
            <div class="btn-big button binding-fill" id="UserBind" >绑定账号</div>
         </div>
    </script>
    <script src="/LiberUI/Scripts/LiberUI.js"></script>
    <script src="/LiberUI/Scripts/LiberUI.Action.js"></script>
    <script>
        Binding = {
            Acnt: {
                acnt: null,
                pass: null,
                openid: null,
                opensrc: null,
                openheadimg: null,
                openname: null
            },
            PhoneFormat: /^1[3,4,5,7,8]{1}[0-9]{9}$/,
            getWxUserInfoEnd: function (rtn) {
                $("#viewOpenUser").fadeIn();
                Binding.Acnt.openheadimg = WxUser.headimgurl;
                Binding.Acnt.openid = WxUser.openid;
                Binding.Acnt.openname = WxUser.nickname;
                $("#userInfo_headImg").attr("src", Binding.Acnt.openheadimg);
                $("#userInfo_tip").vl("欢迎，" + Binding.Acnt.openname);
            },
            confirmBind: function () {
                var phone = $("#wx-phone").vl();
                var pwd = $("#wx-pwd").vl();
                if (!Binding.PhoneFormat.test(phone)) {
                    error("请输入正确的手机号");
                } else {
                    if(pwd.length >= 6&&pwd.indexOf(" ") == -1)
                    {
                        Binding.Acnt.acnt = phone;
                        Binding.Acnt.pass = pwd;
                        $.post("/Register/BindOpenAcnt", Binding.Acnt, function (rtn) {
                            if (rtn.IsPositive) {
                                //用户验证成功，进行微信绑定
                                success("绑定成功！", 3, function () { window.location = "/WxPages/MyBiz/WxIndex.html?tm=" + new Date().getTime().toString(); });
                            }
                            else {
                                error("绑定失败，请检查登录密码或联系客服人员");
                            }
                        });
                       
                    } else {
                        error("密码不能为空");
                    }
                }
            }
        }

        SoBiz.Ready(function () {
            $("#UserBind").on("click", Binding.confirmBind);
        });
        SoBiz.LoginWX(function () {
            Binding.Acnt.opensrc = "wechat";
            Binding.getWxUserInfoEnd();
        });
    </script>
</body>
</html>
